/*
ID:ykzhuji1
PROG:palsquare
LANG:C++
 */
#include <iostream>
#include <fstream>
using namespace std;
char dict[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J'};
int getNumber(int number, int base,char*buffer,int size){
	int length=0;
	int temp=number;
	while(temp){length++;temp/=base;}
	temp=number;
	if(length<=size-1){
		int i=length-1;
		while(temp){buffer[i--]=dict[(temp%base)];temp/=base;}
		buffer[length]=0;
	}
	return length;
} 
bool check(int number, int base, char* buffer, int size){
	bool ret=false;
	int length=0;
	int i;
	if(length=getNumber(number,base,buffer,size)){
		for(i=0;i<=length/2;i++){
			if(buffer[i]!=buffer[length-1-i])break;
		}
		if(i>=length/2)ret=true;
	}
	return ret;
}
int main(){
	ofstream fout("dualpal.out");
	ifstream fin("dualpal.in");
#define MAX 20
	char buffer[MAX];
	char buffer2[MAX];
	int B;
	fin>>B;
	for(int i=1;i<=300;i++){
		if(check(i*i,B,buffer2,MAX)){getNumber(i,B,buffer,MAX);fout<<buffer<<" "<<buffer2<<endl;}
	}
	return 0;
}
